package com.ruoyi.web.controller.work;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.work.domain.WorkSignature;
import com.ruoyi.work.service.IWorkSignatureService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 签名Controller
 *
 * @author fengcheng
 * @date 2025-03-18
 */
@RestController
@RequestMapping("/work/signature")
public class WorkSignatureController extends BaseController {
    @Autowired
    private IWorkSignatureService workSignatureService;

    /**
     * 查询签名列表
     */
    @PreAuthorize("@ss.hasPermi('work:signature:list')")
    @GetMapping("/listWorkSignatureVo")
    public AjaxResult listWorkSignatureVo(WorkSignature workSignature) {
        List<WorkSignature> list = workSignatureService.selectWorkSignatureList(workSignature);
        return success(list);
    }

    /**
     * 查询签名列表
     */
    @PreAuthorize("@ss.hasPermi('work:signature:list')")
    @GetMapping("/list")
    public TableDataInfo list(WorkSignature workSignature) {
        startPage();
        List<WorkSignature> list = workSignatureService.selectWorkSignatureList(workSignature);
        return getDataTable(list);
    }

    /**
     * 导出签名列表
     */
    @PreAuthorize("@ss.hasPermi('work:signature:export')")
    @Log(title = "签名", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WorkSignature workSignature) {
        List<WorkSignature> list = workSignatureService.selectWorkSignatureList(workSignature);
        ExcelUtil<WorkSignature> util = new ExcelUtil<WorkSignature>(WorkSignature.class);
        util.exportExcel(response, list, "签名数据");
    }

    /**
     * 获取签名详细信息
     */
    @PreAuthorize("@ss.hasPermi('work:signature:query')")
    @GetMapping(value = "/{signatureId}")
    public AjaxResult getInfo(@PathVariable("signatureId") Long signatureId) {
        return success(workSignatureService.selectWorkSignatureBySignatureId(signatureId));
    }

    /**
     * 新增签名
     */
    @PreAuthorize("@ss.hasPermi('work:signature:add')")
    @Log(title = "签名", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WorkSignature workSignature) {
        return toAjax(workSignatureService.insertWorkSignature(workSignature));
    }

    /**
     * 修改签名
     */
    @PreAuthorize("@ss.hasPermi('work:signature:edit')")
    @Log(title = "签名", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WorkSignature workSignature) {
        return toAjax(workSignatureService.updateWorkSignature(workSignature));
    }

    /**
     * 删除签名
     */
    @PreAuthorize("@ss.hasPermi('work:signature:remove')")
    @Log(title = "签名", businessType = BusinessType.DELETE)
    @DeleteMapping("/{signatureIds}")
    public AjaxResult remove(@PathVariable Long[] signatureIds) {
        return toAjax(workSignatureService.deleteWorkSignatureBySignatureIds(signatureIds));
    }
}
